<Query Kind="Program" />

void Main()
{
	IFactory factoryA = new FactoryA();
	Product productA = factoryA.CreateProduct();
	productA.MethodSame();
	productA.MethodDo();
	
	IFactory factoryB = new FactoryB();
	Product productB = factoryB.CreateProduct();
	productB.MethodSame();
	productB.MethodDo();
}

abstract class Product{
	public void MethodSame(){
		Console.WriteLine("这是公共方法");
	}
	public abstract void MethodDo();
}

class ProductA : Product
{
	public override void MethodDo()
	{
		Console.WriteLine("这里是产品A");
	}
}

class ProductB : Product
{
	public override void MethodDo()
	{
		Console.WriteLine("这里是产品B");
	}
}

interface IFactory
{
	Product CreateProduct();
}

class FactoryA : IFactory
{
	public Product CreateProduct()
	{
		return new ProductA();
	}
}

class FactoryB : IFactory
{
	public Product CreateProduct()
	{
		return new ProductB();
	}
}